/// Comparison functions for a generic type `T`.
/// These functions provide equality and ordering comparisons.

/// Checks if two references are equal.
///
/// # Type Parameters
///
/// * `T` - The type of the elements to compare.
///
/// # Parameters
///
/// * `location1` - A reference to the first element.
/// * `location2` - A reference to the second element.
///
/// # Returns
///
/// Returns `true` if the two references are equal, `false` otherwise.
pub fn pointer_equal<T>(location1: &T, location2: &T) -> bool {
    std::ptr::eq(location1, location2)
}

/// Compares two references for ordering.
///
/// # Type Parameters
///
/// * `T` - The type of the elements to compare. Must implement `Ord`.
///
/// # Parameters
///
/// * `location1` - A reference to the first element.
/// * `location2` - A reference to the second element.
///
/// # Returns
///
/// Returns:
/// * `-1` if `location1` is less than `location2`.
/// * `1` if `location1` is greater than `location2`.
/// * `0` if `location1` is equal to `location2`.
pub fn pointer_compare<T: Ord>(location1: &T, location2: &T) -> i32 {
    if location1 < location2 {
        -1
    } else if location1 > location2 {
        1
    } else {
        0
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_pointer_equal() {
        let a = 42;
        let b = 42;
        let c = 100;

        assert!(pointer_equal(&a, &b));
        assert!(!pointer_equal(&a, &c));
    }

    #[test]
    fn test_pointer_compare() {
        let a = 42;
        let b = 42;
        let c = 100;

        assert_eq!(pointer_compare(&a, &b), 0);
        assert_eq!(pointer_compare(&a, &c), -1);
        assert_eq!(pointer_compare(&c, &a), 1);
    }
}
